package com.chance.cc.crawler.development.bootstrap.xcar.discounts;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

import java.util.HashMap;
import java.util.Map;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;


/**
 * @ClassName 爱卡经销商采集
 * @Description TODO
 * @Author songding
 * @Date 2021/8/6 13:14
 * @Version 1.0
 *
 *
 **/
public class AkStart {
    private static final String DOMAIN = "xcar";
    private static final String SIDE = "discount";

    public static void main(String[] args) {
        // promotion();//全量车系
        promotionTest();//测试单个城市
    }
    private static Proxy proxy = new Proxy();
    static{
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("H7307T4706B25G4D");
        proxy.setPassword("05B4877CC39192C0");

    }
    //解析明细页链接
    private static void promotion() {
        String url = "https://dealer.xcar.com.cn/";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(DOMAIN)
                .httpConfig(HttpConfig.me(DOMAIN))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 1, null))
                .releaseTime(System.currentTimeMillis())
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .build();
        record.tagsCreator().bizTags().addSite(SIDE);
        record.tagsCreator().bizTags().addSiteBiz(SIDE);
        record.tagsCreator().bizTags().addDomain(DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("domainName", DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("ak47", "爱卡经销商");

        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, turnPageItem)
                .httpUrl("http://192.168.1.217:9599/v1/meta/xcar/keys?site=distributor")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .triggerInfo(DOMAIN, DOMAIN, System.currentTimeMillis(), DOMAIN)
                .crawlerThreadNum(10)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline()
                .fileResultPipeline("F:\\chance_log\\ak\\discount\\kafka-8-3_1.log", false)
                .requestRecord(record)
                .supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.xcar")
                .start();

    }


    private static final Map<String,String> cookieMap = new HashMap();
    static {
        cookieMap.put("","");
        cookieMap.put("","");
        cookieMap.put("","");
        cookieMap.put("","");
        cookieMap.put("","");
    }
    //解析明细页链接  测试单个品牌车
    private static void promotionTest() {
        String url = "https://dealer.xcar.com.cn/";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(DOMAIN, CrawlerEnum.CrawlerRequestType.turnPage)
                .httpUrl(url)
                .domain(DOMAIN)
                .httpConfig(HttpConfig.me(DOMAIN))
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(DOMAIN))
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24 * 1, null))
                .releaseTime(System.currentTimeMillis())
                .httpHead("cookie","__jsluid_h=8b69f245411998b6f0ea95ba7c79c40e; __jsl_clearance=1570598566.464|0|h%2FbOP%2BtfLH%2BdlQOX27DEgliP0II%3D; _Xdwuv=5d9d67a86da0f; _Xdwnewuv=1; uv_firstv_refers=http%3A//dealer.xcar.com.cn/d1000/66.htm%3Ftype%3D1%26page%3D1; _PVXuv=5d9d64a4700af; isRemoveCookie=1; Hm_lvt_53eb54d089f7b5dd4ae2927686b183e0=1570598565; _locationInfo_=%7Burl%3A%22http%3A%2F%2Fsh.xcar.com.cn%2F%22%2Ccity_id%3A%22507%22%2Cprovince_id%3A%222%22%2C%20city_name%3A%22%25E4%25B8%258A%25E6%25B5%25B7%22%7D; fw_slc=1%3A1570598564%3B1%3A1570598956%3B1%3A1570598959%3B1%3A1570599006%3B1%3A1570599007; fw_exc=1%3A1570598562%3B1%3A1570598958%3B1%3A1570598960%3B1%3A1570598961%3B1%3A1570599012; fw_pvc=1%3A1570598564%3B1%3A1570598959%3B1%3A1570598961%3B1%3A1570599006%3B1%3A1570599012; fw_clc=1%3A1570598958%3B1%3A1570598960%3B1%3A1570599029%3B1%3A1570599039%3B1%3A1570599042; _Xdwstime=1570599046; Hm_lpvt_53eb54d089f7b5dd4ae2927686b183e0=1570599043")
                .resultLabelTag(CrawlerEnum.CrawlerDataType.article)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.interaction)
                .resultLabelTag(CrawlerEnum.CrawlerDataType.comment)
                .proxy(proxy)
                .build();
        record.tagsCreator().bizTags().addSite(SIDE);
        record.tagsCreator().bizTags().addSiteBiz(SIDE);
        record.tagsCreator().bizTags().addDomain(DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("domainName", DOMAIN);
        record.tagsCreator().bizTags().addCustomKV("ak47", "爱卡经销商");

        record.tagsCreator().bizTags().addCustomKV("firstCity","全国");
        record.tagsCreator().bizTags().addCustomKV("firstBrand","奥迪");

        DevCrawlerController.builder()
                .triggerInfo(DOMAIN, DOMAIN, System.currentTimeMillis(), DOMAIN)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(DOMAIN))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\xcar\\discount\\discountMessage.log", false)
                .requestRecord(record)
                .build("com.chance.cc.crawler.development.scripts.xcar")
                .start();

    }


  /*  @Test
    public void s() {
        String s = "/d1000/1000.htm?type=1&amp;page=2";
        String ss = "  66.htm?type=1&amp;page=2";
        String sss= "1000.htm?type=1&amp;page=2";
        String s1 = s.substring(7);
        System.out.println(s1);
        String s2 = s1.substring(0,s.length()-22);
        System.out.println(s2);
    }*/
}
